<?php
/*
Primary Author: Derek Shue
Secondary: Alex Arey
Documentation: Cheng Yi
Updated: 12/10/2011
Module Description: The Application module adds/finds/updates/deletes Applications from the database.
*/
class Application_Model_DbTable_Applications extends Zend_Db_Table_Abstract
{

    protected $_name = 'APPLICATIONS';

	public function getApplication($appid)
    {
        $appid = (int)$appid;
        $row = $this->fetchRow('APPID = ' . $appid);
        if (!$row) {
            throw new Exception("Could not find row $appid");
        }
        return $row->toArray();
    }
    public function getApplications($where)
    {
        $rows = $this->fetchAll($where);
        if (!$rows) {
            throw new Exception("Could not find row $where");
        }
        return $rows->toArray();
    }

	public function nextAppID(){
		$sqlquery = $this->select()->from($this->_name, array("MAX(APPID)"));
		$insertrow = $this->fetchRow($sqlquery)->toArray(); 
		return $insertrow["MAX(APPID)"] + 1;
	}
    public function addApplication($sid,$year,$gpa,$transport,$experience,$issuetext,$coursework,$resume,$understandhours,$understandsowo,$understandenroll,$term
)
    {
    	$id = $this->nextAppID();
        $data = array(
			'APPID'=> $id,
			'SID'=> $sid,
			'YEAR'=> $year,
			'GPA'=> $gpa,
			'TRANSPORT'=> $transport,
			'EXPERIENCE'=> $experience,
			'ISSUETEXT'=> $issuetext,
			'COURSEWORK'=> $coursework,
			'RESUME'=> $resume,
			'UNDERSTANDHOURS'=> $understandhours,
			'UNDERSTANDSOWO'=> $understandsowo,
			'UNDERSTANDENROLL'=> $understandenroll,
			'TERM'=> $term,
        );
        $this->insert($data);
        return $id;
    }

    public function updateApplication($appid,$sid,$year,$gpa,$transport,$experience,$issuetext,$coursework,$resume,$understandhours,$understandsowo,$understandenroll,$term
)
    {
        $data = array(
			'SID'=> $sid,
			'YEAR'=> $year,
			'GPA'=> $gpa,
			'TRANSPORT'=> $transport,
			'EXPERIENCE'=> $experience,
			'ISSUETEXT'=> $issuetext,
			'COURSEWORK'=> $coursework,
			'RESUME'=> $resume,
			'UNDERSTANDHOURS'=> $understandhours,
			'UNDERSTANDSOWO'=> $understandsowo,
			'UNDERSTANDENROLL'=> $understandenroll,
			'TERM'=> $term,
        );
        $this->update($data, 'APPID = '. (int)$appid);
    }

    public function deleteApplication($id)    {
        $this->delete('APPID =' . (int)$appid);
    }


}





































































































































